<template>
	<view>
		<uni-list>
			<uni-list-item v-for="(item,index) in addressList" :key="index" 
			@click="addressSelection(index)" showArrow clickable>
				<view slot="body" class="slot-box">
					<text :class="index === activeIndex?'text-main font-md':'font-md'">{{item.area_name}}</text>
				</view>
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: [],
				activeIndex: 0
			}
		},
		onLoad(e) {
			if (e.areaCode) {
				let areaCode = e.areaCode
				console.log(areaCode);
				this.getAddressList(areaCode);
			}
		},
		methods: {
			// 获取热门话题
			getAddressList(code){
				let data={
					areaCode:code,
				};
				this.$H.get('/demo/index/cityAddress',data).then(res=>{
					console.log(res)
					if(res.code==101){
						this.addressList=res.referer;
						console.log(this.addressList);
					}else{
						console.log(res.info);
					}
				})
			},
			addressSelection(index) {
				this.activeIndex = index
				let localDic = this.addressList[index]
				uni.$emit('addressSelect',{
					localDic:localDic
				})
				uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 2
				});
			}
		},
		computed: {

		}
	}
</script>

<style>
	.slot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}
</style>
